package com.example.springbootsfzy.controller.sunkaixuan;

import com.example.springbootsfzy.domain.ConsultationReviews;
import com.example.springbootsfzy.service.sunkaixuan.ConsultationReviewsService;
import com.example.springbootsfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("consultationReviews")
@CrossOrigin
public class ConsultationReviewsController {

    @Autowired
    private ConsultationReviewsService consultationReviewsService;

    //获取所有评价信息
    @GetMapping("/getConsultationReviews")
    public R getConsultationReviews() {
        return R.ok(consultationReviewsService.getConsultationReviews());

    }
    //通过memberid
    @GetMapping("/getConsultationReviewsByMemberId/{memberid}")
    @ResponseBody
    public R getConsultationReviewsByMemberId(@PathVariable int memberid) {
        return R.ok(consultationReviewsService.selectByMemberId(memberid));
    }

    /*
    * 通过consultationId
    * */

    @GetMapping("/getConsultationReviewsByAppointmentId/{consultationId}")
    @ResponseBody
    public R getConsultationReviewsByAppointmentId(@PathVariable int consultationId) {
        return R.ok(consultationReviewsService.selectByAppointmentId(consultationId));
    }


    /*
     * 添加新评价
     * */
    @PostMapping
    @ResponseBody
    public R
    addConsultationReviews(@RequestBody ConsultationReviews consultationReviews) {
        int i = consultationReviewsService.addConsultationReview(consultationReviews);
        if (i > 0) {
            return R.ok("添加成功");
        }else {
            return R.error("添加失败");
        }
    }


    /*
     * 删除
     * */
    @DeleteMapping("/{id}")
    @ResponseBody
    public R deleteByReviewId(@RequestBody int id) {
        int i = consultationReviewsService.deleteByReviewId(id);
        if (i > 0) {
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }

    }


    /*
     * 修改
     * */
    @PutMapping
    @ResponseBody
    public R updateConsultationReview(@RequestBody ConsultationReviews consultationReviews) {
        int i = consultationReviewsService.updateConsultationReview(consultationReviews);
        if (i > 0) {
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }



}
